libxenlight: don't ignore ctx_init errors if there is one.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:44:15 +0000 (11:44 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:44:15 +0000 (11:44 +0000)
ctx_init can return error, and ignoring the errors, would lead to
segfault later. fix all call sites to check return values.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/xl.c

index bc7378c5a963bf41c8a5c03f00315667bc2b4e37..79d2f6cb8819274c28b0ca6e0c584a33b689b5f8 100644 (file)
@@ -762,7 +762,11 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
 start:
     domid = 0;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+
     libxl_ctx_set_log(&ctx, log_callback, NULL);
     libxl_domain_make(&ctx, &info1, &domid);
 
@@ -974,7 +978,10 @@ void set_memory_target(char *p, char *mem)
     struct libxl_ctx ctx;
     uint32_t domid;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
@@ -1016,7 +1023,10 @@ void console(char *p, int cons_num)
     struct libxl_ctx ctx;
     uint32_t domid;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
@@ -1033,7 +1043,10 @@ void cd_insert(char *dom, char *virtdev, char *phys)
     libxl_device_disk disk;
     char *p;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
@@ -1166,7 +1179,10 @@ void pcilist(char *dom)
     libxl_device_pci *pcidevs;
     int num, i;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
@@ -1216,7 +1232,10 @@ void pcidetach(char *dom, char *bdf)
     libxl_device_pci pcidev;
     unsigned int domain, bus, dev, func;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
@@ -1262,7 +1281,10 @@ void pciattach(char *dom, char *bdf, char *vs)
     libxl_device_pci pcidev;
     unsigned int domain, bus, dev, func;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) {
@@ -1310,7 +1332,10 @@ void pause_domain(char *p)
     struct libxl_ctx ctx;
     uint32_t domid;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
@@ -1325,7 +1350,10 @@ void unpause_domain(char *p)
     struct libxl_ctx ctx;
     uint32_t domid;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
@@ -1340,7 +1368,10 @@ void destroy_domain(char *p)
     struct libxl_ctx ctx;
     uint32_t domid;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {
@@ -1356,7 +1387,10 @@ void list_domains(void)
     struct libxl_dominfo *info;
     int nb_domain, i;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     info = libxl_domain_list(&ctx, &nb_domain);
@@ -1383,7 +1417,10 @@ int save_domain(char *p, char *filename, int checkpoint)
     uint32_t domid;
     int fd;
 
-    libxl_ctx_init(&ctx, LIBXL_VERSION);
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        exit(2);
+    }
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
     if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) {